function trim(val)
{
	 return val.replace(/(^\s*)|(\s*$)/g, "");
}
function updateOneInfo(num,info_id,biz_type) { 
		document.getElementById('updateThisInfo'+num).innerHTML = '<img src="/program/admin/images/wait.gif"/>';
		jQuery.ajax( {
			   type: 'POST',
			   url: 'updateOneInfo.jsp',
			   data: 'info_id='+info_id+'&biz_type='+biz_type+'&num='+num,
			   success: function(msg){
				document.getElementById('updateThisInfo'+num).innerHTML=msg;
				 }
			}); 
	}

function ChangeAreaStyle(){
	document.getElementById("area_attr").value = '';
	document.getElementById("areaId1").style.display = 'none';
	document.getElementById("areaId2").style.display = 'block';
}


function isMaxLen(o)
{
	 var nMaxLen=o.getAttribute? parseInt(o.getAttribute("maxlength")):"";
	 if(o.getAttribute && o.value.length>nMaxLen)
	 {
	 	  o.value=o.value.substring(0,nMaxLen);
	 }
}



function selectAll(){
	var checkall = document.getElementById('checkall');
	var listsize = document.getElementById('listsize').value;
	for(var i=0;i<listsize;i++){
		if(checkall.checked){
			document.getElementById('checkone'+i).checked = true;
		}else{
			document.getElementById('checkone'+i).checked = false;
		}
	}
}

function judgeCheck()
{
    var pkid_string = '';
		var listsize = document.getElementById('listsize').value;
		for(var i=0;i<listsize;i++)
		{
				if(document.getElementById('checkone'+i).checked)
				{
					pkid_string += document.getElementById('checkone'+i).value+'|';
				}
		}
    return pkid_string;
}

//var one_member_price ='';


function judgePayCheck()
{
    var payid_string = '';
		var paylistsize = document.getElementById('paylistsize').value;
		for(var i=0;i<paylistsize;i++)
		{
				if(document.getElementById('payment'+i).checked)
				{
					payid_string += document.getElementById('payment'+i).value+'|';
				}
		}
    return payid_string;
}


function changeTime(){

	var obj = document.getElementById('up_operating').value;
	if( obj == '' || obj.indexOf('-')>-1 || obj.indexOf('c')>-1 || obj.indexOf('d')>-1 ){
		document.getElementById('b_g').style.display = 'none';
	}else{
		document.getElementById('b_g').style.display = 'inline';
	}
}

function operateInfo(val){

	var oper = document.getElementById(val+'_operating').value;
	if(oper == ''){
		alert('请选择操作方式!');
		return false;
	}

	var listsize = document.getElementById('listsize').value;

	var pkid_string = judgeCheck();
	if( pkid_string == '' ){
		alert('请至少选择一条商品进行操作!');
		return false;
	}
	if( oper == '-' ){
		document.getElementById('pkid').value = pkid_string;
		document.indexForm.action = '/doTradeReg.do';
		document.getElementById('bpm_id').value = '5127';
		if(window.confirm('确认删除吗?')){
			document.indexForm.submit();
		}
 	} else if( 'abcd'.indexOf(oper) > -1 ) {
		document.getElementById('pkid').value = pkid_string;
		document.indexForm.action='/doTradeReg.do';
		document.getElementById('bpm_id').value = '8332';
		if(window.confirm('确认提交吗?')){
			document.indexForm.submit();
		}
	} else {
		document.getElementById('pkid').value = pkid_string;
		document.indexForm.action='/doTradeReg.do';
		document.getElementById('bpm_id').value = '2491';
		if(window.confirm('确认提交吗?')){
			document.indexForm.submit();
		}
	}

}

function deleteOneInfo(pkid,bpm_id)
{

	if(window.confirm('确认删除吗？'))
	{
	  window.location.href='/doTradeReg.do?pkid='+pkid+'&bpm_id='+bpm_id;
 	}
}




function subForm(){

	//------  biz attr validate
	var attrSize = document.getElementById('attrsize').value;
	var attr_value = '';
	for( var j = 0; j < attrSize; j++ )
	{
		var item;
		var attrStr ='';
		var attrId = document.getElementById('attr_id'+j).value;
		var attrName = document.getElementById('attr_name'+j).value;
		var conType = document.getElementById('con_type' + j).value;
		var defaultTag = document.getElementById('default_tag' + j).value;

		// select
		if(conType == '0'){
		  attrStr= document.getElementById('attr_value'+j).value;
			if( attrStr == '' && defaultTag == '0'){
				alert('请选择' + attrName + '！'  );
				return;
			}
		}

		// input
		if(conType == '1'){
				attrStr = document.getElementById('attr_value'+j).value;
				if( attrStr == '' && defaultTag == '0'){
					alert('请输入' + attrName+'！');
					//document.getElementById('attr_id'+j).focus();
					return;
				}
		}

		//chechbox
		if( conType == '2'){
			var valueSize = document.getElementById('valuesize'+j).value;
			for( var r = 0; r < valueSize; r++ ){
				 if( document.getElementById('attr_value'+j+'_'+r).checked){
					attrStr +=  document.getElementById('attr_value'+j+'_'+r).value + '|';
				 }
			}
			if( attrStr == '' && defaultTag=='0'){
				alert('请选择' + attrName+'！' );
				return;
			}
		}
		if(attrStr != ''){
			item = attrId+"|"+attrStr;
			attr_value += item +',';
		}
	}

	document.getElementById('attr_desc').value = attr_value;

	if(trim(document.getElementById('biz_type').value)==''){
	  alert('请选择商机类型！');
	  document.getElementById('biz_type').focus();
	  return;
	}
	if(trim(document.getElementById('title').value)==''){
	  alert('请输入信息标题！');
	  document.getElementById('title').focus();
	  return;
	}
	var str = CKEDITOR.instances.content.getData();
	str = trim(str);
	if(str == ''){
		alert('请输入详细说明!');
		CKEDITOR.instances.content.focus();
		return;
	}
	if(CKEDITOR.instances.content.getData().length>60010){
		alert("详细说明不能大于60000个字符！");
		return;	
	}
	if(trim(document.getElementById('biz_price').value)==''){
	  alert('请输入供应价格！');
	  document.getElementById('biz_price').focus();
	  return;
	}
	if(trim(document.getElementById('mini_supply').value)==''){
	  alert('请输入最小量！');
	  document.getElementById('mini_supply').focus();
	  return;
	}
	if(trim(document.getElementById('max_supply').value)==''){
	  alert('请输入商品总量！');
	  document.getElementById('max_supply').focus();
	  return;
	}

	var n = 0;

	var smObj = document.getElementsByName('end_date');
	for (var i = 0; i < smObj.length; i++){
		if(smObj[i].checked) {
			n++;
		}
	}
	var payid_string = judgePayCheck();
	if( payid_string == '' ){
		alert('请选择商品支付方式!');
		return false;
	}
	document.getElementById('payid').value = payid_string;
	if(n == 0){
		alert('请选择信息有效期！');
		return;
	}

	/*
	var objs = '';
	var statecode = document.getElementsByName("statecode");
	for (var i = 0; i < statecode.length; i++){
		if(statecode[i].checked) {
			objs += statecode[i].value;
		}
	}
	document.getElementById('state_code').value = 'c' + objs;
	*/

	document.addForm.submit();

}

function searchForm(){

	document.indexForm.submit();

}

function setProvince()
{
	Ts_areaInfo.getAreaClassByUpId('000000000000000',function(data){
		DWRUtil.removeAllOptions('province');
		DWRUtil.addOptions('province',{'':'请选择'});
		DWRUtil.addOptions('province',data);
	})
}
function setCitys(prov)
{
   var provence=prov;
	 Ts_areaInfo.getAreaClassByUpId(provence,function(data){
		DWRUtil.removeAllOptions('eparchy_code');
		DWRUtil.addOptions('eparchy_code',{'':'请选择'});
		DWRUtil.addOptions('eparchy_code',data);
		DWRUtil.removeAllOptions('city_code');
		DWRUtil.addOptions('city_code',{'':'请选择'});
	});
}

function setAreas(city_id){
	Ts_areaInfo.getAreaClassByUpId(city_id,function(data){
	 	DWRUtil.removeAllOptions('city_code');
		DWRUtil.addOptions('city_code',{'':'请选择'});
	 	DWRUtil.addOptions('city_code',data);
	});
}

function check(){
	if (document.all.myform.myuser.value.indexOf(" ")>=0 || document.all.myform.myuser.value.indexOf("　")>=0){ //前面判断英文空格，后面判断中文空格
		alert("不能存在空格"); 
		document.all.myform.myuser.focus(); 
		document.all.myform.myuser.value==""; 
		return false;

	} 
}

//限制数字全角状态输入 允许中文输入
function   clearSBC(){ 
window.clipboardData.setData( 'text ',clipboardData.getData( 'text ').replace(/[\uFF00-\uFFFF]/g, ' ')) 
} 